package com.example.fengyungo.controller.user.user;

import com.example.fengyungo.constant.DriverConstant;
import com.example.fengyungo.constant.MsgConstant;
import com.example.fengyungo.domain.pojo.Driver;
import com.example.fengyungo.domain.pojo.User;
import com.example.fengyungo.result.Result;
import com.example.fengyungo.service.DriverService;
import com.example.fengyungo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/user/user")
public class UserDriverController {

    @Autowired
    private DriverService driverService;

    /**
     * 根据订单编号获取司机信息
     *
     * @return Result
     */
    @GetMapping("/getDriversByOrderNumber/{number}")
    public Result<List<Driver>> getDriversByOrderNumber(@PathVariable String number) {
        List<Driver> driversByOrderNumber = driverService.getDriversByOrderNumber(number);
        return Result.success(driversByOrderNumber);
    }

    /**
     * 根据司机id获取司机信息
     *
     * @param id 司机id
     * @return Result
     */
    @GetMapping("/driver/{id}")
    @Cacheable(value = "driver", key = "'getDriverById'+#id")
    public Result<Driver> getDriverById(@PathVariable String id) {
        Driver driver = driverService.getDriverById(id);
        if (driver == null) {
            return Result.error(DriverConstant.DRIVER_NOT_EXIST);
        } else {
            return Result.success(driver);
        }
    }
}
